home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 005 / product.arc / ZOOOM.DOC < prev    next >
Encoding:
Text File  |  1986-11-06  |  4.6 KB  |  113 lines

  1. Enitity Access Fun with AutoLISP Version 2.5
  2.  
  3. ZOOOM!        by Ted Schaefer        10/7/86
  4.  
  5.  
  6. Let's have some fun with AutoLISP.  We'll create an AutoLISP
  7. routine, ZOOOM, which borders on animation.  ZOOOM will take the
  8. last block inserted in a drawing, scale it up a little and repeat
  9. the process  20 times. The only difference between this process
  10. and true animation is the speed of the computer.  
  11.  
  12. Because this involves enitity access, the ZOOOM routine requires
  13. AutoCAD Version 2.5. What we'll do is take the last entity,  pull
  14. out the scale factors for X and Y (there is a Z).  Then they will
  15. be rescaled by multiplying them by 1.25.   The new scale factors
  16. then will be substituted  for the old ones.  Finally, the entity
  17. description will be used to update the inserted block.
  18.  
  19. Here's the ZOOOM routine:
  20.  
  21.  1.        (DEFUN C:ZOOOM ()
  22.  2.
  23.  3.    (setq e (entget (entlast)))
  24.  4.    (setq oldx (assoc 41 e))
  25.  5.    (setq oldy (assoc 42 e))
  26.  6.    (setq scalex (* (cdr oldx) 1.25))
  27.  7.    (setq scaley (* (cdr oldy) 1.25))
  28.  8.
  29.  9.        (REPEAT 20
  30.  10.
  31.  11.   (setq new41 (cons 41 scalex))
  32.  12.   (setq new42 (cons 42 scaley))
  33.  13.
  34.  14.   (setq scalex (* scalex 1.25))
  35.  15.   (setq scaley (* scaley 1.25))
  36.  16.
  37.  17.   (setq e (subst new41 oldx e))
  38.  18.   (entmod  (setq e (subst new42 oldy e)))
  39.  19.(setq oldx new41)
  40.  20.(setq oldy new42)
  41.  21.)
  42.  22.       )
  43.  
  44. (The line numbers are for reference only, not to be typed in.)
  45.  
  46. What do the lines mean?  Line 1 says that we're defining a
  47. function.   With the "C:" we're saying we want the function to
  48. behave just like another AutoCAD command, such as LINE or BREAK.
  49.  
  50. The command will be executed from AutoCAD's command prompt by
  51. typing in the word ZOOOM.  Note that we had to use a name
  52. slightly different than a normal AutoCAD command.  At the end of
  53. the line are two parentheses, where local variables can be
  54. defined.  We won't bother.
  55.  
  56. Line 2 finds the name of the last entity with the  "entlast"
  57. command.   Then, using "entget", we "get" all the properties of
  58. the entity whose name was specified with "entlast".  We then
  59. store those properties in a variable "e" using the "setq"
  60. command.
  61.  
  62. After running ZOOOM,  you can type !e,  and examine the contents
  63. of this variable.  What you'll see is about three line of text
  64. grouped with parentheses.  Within each group is a code number and
  65. a value.  The number and the value form a "list".  The codes  are
  66. spelled out by the AutoCAD DXF format.   The code numbers for the
  67. X and Y scale factors are 41 and 42.   Lines 4 and 5 use  the 
  68. "assoc" command to break out the values and assign them to the
  69. variables "oldx" and "oldy".
  70.  
  71. Lines 6 and 7 then multiply the scale factors and store them in
  72. variables "scalex" and "scaley".  You can change the 1.25
  73. multiplier for different effects.
  74.  
  75. We now have the information needed to go into the repeating loop
  76. at line 9, which is set for 20 repetitions.   Lines 11 and 12
  77. construct the new lists containing the code number and increased
  78. scale  factors  using  the  "cons"  command.   The lists are then
  79. stored under variables "new41" and "new42".
  80.  
  81. In lines 14 and 15, the  scale  factors are increased and stored
  82. under their old variable names.
  83.  
  84. Next, we must substitute our new lists with increased scale
  85. factors into the complete description of  the  symbol/block
  86. (or  entity).   This is done on lines 17 and 18 using the "subst"
  87. command.  Line 18 goes further.   Using the "entmod" command,  we
  88. modify the entity whose name and description are stored under the
  89. variable  "e"  which we have changed.   This produces the visible
  90. change on the screen.
  91.  
  92. Now the new scale factors have been used; therefore, they're old!
  93. Lines 19 and 20 assign new to old. This is the end of the loop.
  94. The  program  then  returns to line 9 and repeats the steps
  95. between 9 and 21. Line 21 closes off the end of the REPEAT loop
  96. and 22 closes the DEFUN.
  97.  
  98. Well,  that  was  fun,  but what kind of serious work can be done
  99. with entity access?   How about a command call TEXTFIT  that
  100. allows  you  to  move text and squeeze it or expand it without
  101. changing styles?   How about an EXPORT routine that takes text
  102. off your drawing and puts it in a word processing file?  How
  103. about a command called FIND that searches your drawing and counts
  104. the  number  of occurrences of anything?   How about a command
  105. called PLENGTH that measures the length of a polyline without
  106. using the LIST command?
  107.  
  108. What a about a command that searches your drawing for text of one
  109. size and converts it  to  another?    Or  changes  one  style  to
  110. another?  Your imagination is the only limit to the
  111. possibilities.  ZOOOOOOOM on!
  112.  
  113. End